Test statistics

The test statistics used by PermutationTests.jl are computed by the several methods of the statistic function listed here below. You do not need to use them to carry out permutation tests, however they are exported because they may turn useful. For general usage of this package you can skip this page.

All statistic methods take a singleton of the Statistic type and other arguments to yield a specific test-statistic.

All test statistics are grouped in four Statistic groups.


PermutationTests.statisticFunction
function statistic(x::UniData, y::UniData, stat::PearsonR; 
                standardized::Bool=false, 
                centered::Bool=false, 
                means::Tuple=(), 
                sds::Tuple=(), kwargs...)

Pearson product-moment correlation r statistic of input data vector x and y.

If the means and/or standard deviations of x and y are passed as tuple means and sds, respectively, they are not computed.

If centered is true, the two vectors are assumed to have zero mean.

If standardized is true both x and y are assumed standardized, thus only the cross-product needs to be computed. This is by far the most efficient way if this function is to be called repeatedly on the same data input vectors and for computing p-values by data permutations as the cross-product is en equivalent test statistic for the Pearson correlation if the data is standardized.

Examples

using PermutationTests
x, y = randn(10), randn(10);
c1 = statistic(x, y, PearsonR())

zx=μ0σ1(x);
zy=μ0σ1(y);
c2 = statistic(zx, zy, PearsonR(); standardized=true)

see μ0σ1

source
function statistic(x::UniData, y::UniData, stat::Covariance; 
                centered::Bool=false, 
                means::Tuple=(), 
                kwargs...)

Covariance of data input vectors x and y.

Equivalent to the Pearson correlation r test statistic for bi-directional correlation tests, see Statistic.

For the optional keyword arguments, see the method statistic(x, y, stat::PearsonR).

Examples

using PermutationTests
x, y = randn(10), randn(10)
c1 = statistic(x, y, Covariance())

c2 = statistic(μ0(x), μ0(y), Covariance(); centered=true)

μx=μ(x)
μy=μ(y)
c3 = statistic(x, y, Covariance(); means=(μx, μy))

see μ0, μ

source
function statistic(x::UniData, y::UniData, stat::CrossProd; 
                kwargs...)

Cross-product (inner product) of data input vectors x and y.

Equivalent to the Pearson correlation r test statistic for directional correlation tests and always if the data is standardized, see Statistic.

Examples

using PermutationTests
x, y = randn(10), randn(10)
c = statistic(x, y, CrossProd())
source
function statistic(x::IntVec, y::UniData, stat::AnovaF_IS; 
                k::Into=nothing, 
                ns::Union{Vector{Int}, Nothing}=nothing, 
                kwargs...) 

F statistic of the 1-way ANOVA for independent samples, see Edgington (1995), p. 60.

The data is given as an unique vector y, holding the observations for each group in the natural order, thus for $K$ groups y holds $N=N_1+ \ldots +N_K$ elements, where $N_k$ is the number of observations for the $k^{th}$ group.

x is the membership(::IndSampStatistic) vector.

k is the number of groups (independent samples). If omitted it will be computed.

ns is the group numerosity vector with form ns=[N1,..., NK]. If omitted it will be computed.

Examples

using PermutationTests
g1=[1.0, 2.0, 3.0, 4.0] # observations for group 1 
g2=[1.1, 2.8, 3.2, 4.4, 5.3] # observations for group 2 
ns=[length(g1), length(g2)] # N1, N2
y=vcat(g1, g2)
x=membership(AnovaF_IS(), ns)
F=statistic(x, y, AnovaF_IS())
# or, to avoid finding k and ns from y
F2=statistic(x, y, AnovaF_IS(); k=2, ns=ns)

# The square of the t test statistic for independent samples for a bi-directional test
# is equal to the above F test statistics

t=statistic(x, y, StudentT_IS(); ns=ns)
println(t^2≈F ? "OK" : "error")
source
function statistic(x::IntVec, y::UniData, stat::SumGroupTotalsSq_IS; 
                k::Into=nothing, 
                kwargs...)

Sum of squared group totals.

Equivalent to the 1-way ANOVA for independent samples F test statistic in balanced designs, see Statistic.

For optional keyword argument k, see the statistic method for AnovaF_IS here above.

source
function statistic(x::IntVec, y::UniData, stat::SumGroupTotalsSqN_IS; 
                k::Into=nothing, 
                ns::Union{Vector{Int}, Nothing}=nothing, 
                kwargs...)

Sum of squared group totals divided each by the group numerosity.

Equivalent to the 1-way ANOVA for independent samples F test statistic in general, see Statistic.

For optional keyword arguments k and ns and for examples, see the statistic method for AnovaF_IS here above.

source
function statistic(x::IntVec, y::UniData, stat::StudentT_IS; 
                k::Into=nothing, 
                ns::Union{Vector{Int}, Nothing}=nothing, 
                kwargs...)

Student's t statistic for independent samples, see Edgington (1995), p. 3.

For all arguments except stat and examples see the statistic method for AnovaF_IS here above.

source
function statistic(x::IntVec, y::UniData, stat::Group1Total_IS; 
                kwargs...)            

Sum of observations for group 1.

Equivalent to the Students's t test statistic for independent samples for diretional tests, see Statistic.

For arguments x and y and for examples, see the statistic method for AnovaF_IS here above.

source
function statistic(x::IntVec, y::UniData, stat::AnovaF_RM; 
                ns::@NamedTuple{n::Int, k::Int}, 
                ∑Y²kn::Realo=nothing, 
                ∑y²::Realo=nothing, 
                ∑S²k::Realo=nothing, 
                kwargs...) 

F statistic of 1-way ANOVA for repeated measures, see Edgington (1995), p. 102.

The data is given as an unique vector y concatenaning the $N$ observations for the $K$ measures (treatments, time, ...) in the natural order, that is, the $K$ treatments for observation 1, ..., the $K$ tratments for observation $N$. Thus, y holds $N \cdot K$ elements.

x is the membership(::RepMeasStatistic) vector.

ns is a julia named tuple with form (n=N, k=K) (see examples below).

∑Y²kn, ∑y² and ∑S²k can be optionally provided to speed up computations since these quantities are invariant by data permutations. The exported function _∑Y²kn_∑y²_∑S²k can be used for this purpose, see the examples below.

Examples

using PermutationTests
# K=2 (measurements), N=4 (observations)
o1=[1.0, 2.0]; # first observation 
o2=[2.0, 2.8]; # second observation 
o3=[3.0, 2.6]; # third observation
o4=[4.0, 4.1]; # fourth observation
ns=(n=4, k=2); # four obs. and two measurements
y=vcat(o1, o2, o3, o4);
x=membership(AnovaF_RM(), ns);
F=statistic(x, y, AnovaF_RM(); ns=ns)

# pre-compute some data
pcd=_∑Y²kn_∑y²_∑S²k(y, ns);
F2=statistic(x, y, AnovaF_RM(); ns=ns, ∑Y²kn=pcd[1], ∑y²=pcd[2], ∑S²k=pcd[3])

# The t test statistic for repeated measures is the same as the one-sample 
# t test statistic on the difference of the two measurements. 
# The square of those statistics for a bi-directional test are equal to 
# the above F test statistics. 

x=membership(StudentT_1S(), ns.n)
t=statistic(x, y[1:2:ns.n*2-1].-y[2:2:ns.n*2], StudentT_1S())
println(t^2≈F ? "OK" : "error")
source
function statistic(x::IntVec, y::UniData, stat::SumTreatTotalsSq_RM; 
                ns::@NamedTuple{n::Int, k::Int}, 
                kwargs...)

Sum of squared treatment totals.

Equivalent to the 1-way ANOVA for repeated measures F test statistic in general, see Statistic.

For optional keyword argument ns see the statistic method for AnovaF_RM here above.

source
function statistic(x::Tuple, y::UniData, stat::StudentT_1S; 
                ∑y²::Realo=nothing, 
                kwargs...) 

Student's one-sample t statistic.

y is the input data.

x is a tuple holding as many 1.0 as elements in y.

∑y² can be optionally provided to speed up computations, since this quantity is invariant by data permutations. The exported function _∑y² can be used for this purpose, see the examples below.

Examples

using PermutationsTest
y=randn(6);
x=(1., 1., 1., 1., 1., 1.);
t=statistic(x, y, StudentT_1S()) 

pcd=_∑y²(y)
t2=statistic(x, y, StudentT_1S(); ∑y²=pcd) 
println(t≈t2 ? "OK" : "Error")
source
function statistic(x::UniData, y::UniData, stat::StudentT_1S; 
                ∑y²::Realo=nothing, 
                kwargs...)

Student's one-sample t statistic.

y is the input data.

x is the membership(::OneSampStatistic) vector.

∑y² can be optionally provided to speed up computations since this quantity is invariant by data permutations. The exported function _∑y² can be used for this purpose, see the examples below.

Examples

using PermutationsTest
y=randn(6);
x=membership(StudentT_1S(), length(y));
t=statistic(x, y, StudentT_1S()) 

pcd=_∑y²(y)
t2=statistic(x, y, StudentT_1S(); ∑y²=pcd) 
println(t≈t2 ? "OK" : "Error")
source
function statistic(x::Tuple, y::UniData, stat::Sum; 
                kwargs...) 
source
function statistic(x::UniData, y::UniData, stat::Sum; 
                kwargs...)  

Sum of the elements in input data vector y.

Equivalent to the one-sample t test statistic in general, see Statistic.

x is the membership(::OneSampStatistic) vector.

source